package io.gitee.icefairy.total_monitor.model;

import io.gitee.icefairy.total_monitor.handler.AutoCompleteHandler;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.AutoCompleteType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Author:icefairy
 * Date:2021/12/13 0013
 **/
@Erupt(name = "Item", orderBy = "groupSet asc,project asc,compent asc,lastActive desc")
@Table(name = "z_item")
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Item implements Serializable {
    @Id
    @GeneratedValue(
            generator = "generator"
    )
    @GenericGenerator(
            name = "generator",
            strategy = "native"
    )
    @Column(
            name = "id"
    )

    @EruptField(views = @View(title = "ID"), edit = @Edit(title = "ID", show = false))
    private Long id;
    @EruptField(views = @View(title = "分组"), edit = @Edit(title = "分组", search = @Search, type = EditType.AUTO_COMPLETE, autoCompleteType = @AutoCompleteType(handler = AutoCompleteHandler.class, param = {"0"})))
    private String groupSet;
    @EruptField(views = @View(title = "项目"), edit = @Edit(title = "项目", search = @Search, type = EditType.AUTO_COMPLETE, autoCompleteType = @AutoCompleteType(handler = AutoCompleteHandler.class, param = {"1"})))
    private String project;
    @EruptField(views = @View(title = "组件"), edit = @Edit(title = "组件", search = @Search))
    private String compent;
    @EruptField(views = @View(title = "上次活动", type = ViewType.DATE), edit = @Edit(title = "上次活动", type = EditType.DATE, dateType = @DateType(type = DateType.Type.DATE_TIME)))
    private Date lastActive;
    @EruptField(views = @View(title = "备注"), edit = @Edit(title = "备注", search = @Search, type = EditType.TEXTAREA))
    @Lob
    private String note;
    @EruptField(views = @View(title = "额外数据", show = false), edit = @Edit(title = "额外数据", search = @Search, type = EditType.TEXTAREA))
    @Lob
    private String extra;
    @EruptField(views = @View(title = "维护手册"), edit = @Edit(title = "维护手册", type = EditType.HTML_EDITOR))
    @Lob
    private String maintain;
    @EruptField(views = @View(title = "状态", type = ViewType.BOOLEAN), edit = @Edit(title = "状态", type = EditType.BOOLEAN))
    private boolean status;
    @EruptField(views = @View(title = "IP"), edit = @Edit(title = "IP"))
    private String ip;
}
